import Taro from '@tarojs/taro';
import { create } from 'zustand';
import { immer } from 'zustand/middleware/immer';
import { createReportRecord } from '@/business/services/user/userInfo';

/**
 * @description 新增举报
 * @author Shawn
 */

type RequestFunction = (params: any) => Promise<void>;

type State = {
  // 举报返回结果
  createReportRes: any;
};

type Actions = {
  // 新增举报记录
  createReport: RequestFunction;
};

const initialState: State = {
  createReportRes: {},
};

export const createReportStore = create<State & Actions>()(
  immer((set) => ({
    ...initialState,

    /**
     * 新增举报记录
     */
    createReport: async (params: any) => {
      try {
        Taro.showLoading({
          title: '加载中',
        });

        const res = await createReportRecord(params);
        if (res.success) {
          set((state) => {
          state.createReportRes = res.data;
          });
        }
        
        return res 
      } catch (error) {
        console.log('举报失败', error);
      } finally {
        Taro.hideLoading();
      }
    },
  })),
);
